// src/store/modules/userModule.ts
// import { UserState } from '@/types';

export interface UserInfo {
  token?: string;
}

export interface UserState {
  userInfo: UserInfo;
}

const userModule = {
  namespaced: true as const,
  state: (): UserState => ({
    userInfo: JSON.parse(localStorage.getItem('userInfo') || '{}')
  }),
  mutations: {
    setUserInfo(state: UserState, info: any) {
      state.userInfo = info;
      localStorage.setItem('userInfo', JSON.stringify(info));
    }
  },
  actions: {
    logout({ commit }: { commit: Function }) {
      commit('setUserInfo', {});
      commit('cart/setCartList', [], { root: true });
    }
  }
};

export default userModule;